package com.mifengs.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.mifengs.mall.R;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.util.ImageLoadUtil;

/**
 * Created by lihaoqi on 2017/12/20.
 */

public class HomeTitleAdapter extends DelegateAdapter.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private FloorBean floorBean;
    public HomeTitleAdapter(Context context) {
        this.mContext = context;
    }
    public void setFloorData(FloorBean floorBean){
        this.floorBean = floorBean;
        notifyDataSetChanged();
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new LinearLayoutHelper();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TitleViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_title,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof  TitleViewHolder){
            TitleViewHolder titleViewHolder = (TitleViewHolder) holder;
            if(floorBean !=null){
                for(int i = 0;i<floorBean.getAdverts().size();i++ ){
                    AdvertBean adverts = floorBean.getAdverts().get(i);
                    ImageLoadUtil.displayImage(mContext,adverts.getImg(),titleViewHolder.titleView);
                }
            }
        }
    }

    @Override
    public int getItemCount() {
        return 1;
    }


    public class TitleViewHolder extends RecyclerView.ViewHolder{

        public ImageView titleView;

        public TitleViewHolder(View itemView) {
            super(itemView);
            titleView = itemView.findViewById(R.id.iv_title);
        }
    }

}
